﻿#include "SendCommonMsg.h"

#include <QtNetwork>
#include <memory>

SendComMsg::SendComMsg(QObject *parent) : QObject(parent)
{

}

void SendComMsg::toSendQueue(MsgType type)
{
    auto sendMsg = new MESG{type, 0, 0, nullptr};
    g_sendQueue.push_msg(sendMsg);
}

void SendComMsg::toSendQueue(MsgType type, QByteArray data)
{
    std::shared_ptr<uchar[]> tmpData(new uchar[data.size()]);
    memcpy(tmpData.get(), data, data.size());

    auto sendMsg = new MESG{type, static_cast<quint32>(data.size()),
              QHostAddress::LocalHost, tmpData};

    g_sendQueue.push_msg(sendMsg);
}

void SendComMsg::toSendJoinMsgQueue(MsgType type, quint32 roomNo)
{
    std::shared_ptr<uchar[]> tmpData(new uchar[14]);
    memset(tmpData.get(), 0, 14);
    qToBigEndian(roomNo, tmpData.get());
//    memcpy(tmpData.get(), &roomNo, sizeof(roomNo));

    auto sendMsg = new MESG{type, 4, 0, tmpData};

    g_sendQueue.push_msg(sendMsg);

}
